package com.android.gufengmall.gen;

import com.google.gson.Gson;

import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.ArrayList;
import java.util.List;

//评论数据集合装换存储类
public class InfoConverter implements PropertyConverter<List<CommentBean>,String> {
    @Override
    public List<CommentBean> convertToEntityProperty(String databaseValue) {
        if (databaseValue == null) {
            return null;
        }
        String[] StrList = databaseValue.split("~");
        List<CommentBean> transPortList = new ArrayList<>();
        for (String s : StrList) {
            transPortList.add(new Gson().fromJson(s,CommentBean.class));
        }
        return transPortList;
    }

    @Override
    public String convertToDatabaseValue(List<CommentBean> entityProperty) {
        if (entityProperty == null) {
            return null;
        } else {
            StringBuilder stringBuilder = new StringBuilder();
            for (CommentBean array : entityProperty) {
                String str = new Gson().toJson(array,CommentBean.class);
                stringBuilder.append(str);
                stringBuilder.append("~");
            }
            return stringBuilder.toString();
        }
    }
}
